package socketinterface;

import java.io.DataInputStream;
import java.io.IOException;

import com.vast.ui.component.models.Led;
import com.vast.ui.ledpanel.views.ViewPart;

public class UpdateLed implements ICommandPacket {
	public  ViewPart          view;
	private DataInputStream   in;
	private Logger            logger;
	
	public UpdateLed(ViewPart view, DataInputStream   in, Logger logger) {
		this.view   = view;
		this.in     = in;
		this.logger = logger;
	}
	
	public void execute() throws IOException {
		// TODO Auto-generated method stub
		final int index  = in.readInt();
		int value        = in.readInt();
		short endMarker = in.readShort();
		if (endMarker != 0x7FFF) {
				logger.writeEntry("EndMarker is broken. : EndMarker = 0x" + Integer.toHexString((int)endMarker) + " (" + Integer.toString((int)endMarker) + ")");
		}
		
		final Led led = new Led(view., value);

			view.ledPanel.changeTarget(columnIndex, led);
			view.display.syncExec(new Runnable() {
				public void run() {
					view.viewer.setInput(view.ledPanel);
				}
			});
		}
		
	}

}
